var express = require('express');
var router = express.Router();
var execSql = require('../db/dbMysql.js');

//首页轮播图接口：
router.get('/banners',async(req,res)=>{
  //查询轮播图数据
  let sql = `select id,concat('http://127.0.0.1:3000/',image_src) as image_src,title from e_banners where isshow='1'`;

  let [err,arr] = await execSql(sql);
  if(err){
    res.send({status:200,msg:'轮播图查询成功',data:arr});
  }else{
    res.send({status:500,msg:'轮播图查询失败'});
  }
});

//前端同步课程接口
router.get('/course',async(req,res)=>{
  //接掺，1为同步  2为精品
  let {tid = 1 , limits = 8} = req.query;
  //查询同步课程/精品课程数据
  let sql = `select cid,title,price,concat('http://127.0.0.1:3000/course/',image_src)as image_src,type_name,area_name,subject_name from e_course where type='${tid}' limit ${limits}`;
  let [err,arr] = await execSql(sql);
  if(err){
    res.send({status:200,msg:'同步课程查询成功',data:arr});
  }else{
    res.send({status:500,msg:'同步课程查询失败'});
  }
});


module.exports = router;
